local Workspace = game:GetService("Workspace")

--开发过程中 测试模块，各种快捷键--- 服务器

local ServerOHOH = _G.ServerOHOH;

local EventList = ServerOHOH.load.EventList();
EventList.DataDebug=true

local ServerEventManager = ServerOHOH.load.ServerEventManager();

local DataBaseManager = ServerOHOH.load.DataBaseManager();
local OHOHEnum = ServerOHOH.load.OHOHEnum();

local M = ServerOHOH.class.new(script, ServerOHOH.files.BaseComponent());

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, ...)
	M.super.ctor(self, ...);

	print("XXXXXXXXXXXXXDebugDebugDebugDebugDebugXXXXXXXXXXXXXXXXXXXXXX")
end;

function M.Debug(self,actionId,textArg,otherArg)

	print("XXXXXXXXXXXDebugXXXXXXXXXXXXXXXXXXXXXXXX",actionId,textArg,otherArg)
	local fuc=self[actionId]
	if fuc then
		fuc(self,textArg,otherArg)
	end
end

function M.Skibi_killed(self)


end

function M.AddLucky(self,textArg,otherArg)
	local num=tonumber(textArg)
	self.parent:GetComponent(ServerOHOH.load.Server_ItemCtrl()):AddItem({Points_lucky=num},true,true)
end

function M.ClearDataByUserID(self,textArg,otherArg)
	DataBaseManager:Clear(OHOHEnum.data_base.player_data, tonumber(textArg), function()
	end);
end

function M.ClearData(self,textArg,otherArg)
	self.parent:GetComponent(ServerOHOH.load.Server_PlayerDataComponent()):Clear()
end
	
function M.Dead(self,textArg,otherArg)
	self.parent.character:GetHumanoid().Health=0

end

function M.AddPower(self,textArg,otherArg)
	local num=tonumber(textArg)
	self.parent:GetComponent(ServerOHOH.load.Server_ItemCtrl()):AddItem({base_power=num},true,true)
end

function M.AddWins(self,textArg,otherArg)
	local num=tonumber(textArg)
	self.parent:GetComponent(ServerOHOH.load.Server_ItemCtrl()):AddItem({base_wins=num},true,true)
end

function M.AddDiamond(self,textArg,otherArg)
	local num=tonumber(textArg)
	self.parent:GetComponent(ServerOHOH.load.Server_ItemCtrl()):AddItem({base_diamond=num},true,true)
end

function M.PrintTestALLDATA(self,textArg,otherArg)
	self.parent:GetComponent(_G.CommonOHOH.load.Common_ActionSynchronize()):PrintTestALLDATA()
end

function M.PrintUserData(self,textArg,otherArg)
	local data=self.parent:GetComponent(ServerOHOH.load.Server_PlayerDataComponent())

	-- ServerOHOH:PrintTable(data:GetData("levels"))

	data:Print()

    -- print("=====================A============================>>>")
	-- print(data:GetData("levels")[1].count)
	-- print(data:GetData("levels")[1].userId)

	-- ServerOHOH:PrintTable(data:GetData("levels")[1].statistics)

	-- print("=====================B============================>>>")

    -- ServerOHOH:PrintTable(data:GetData("levels")[11])

end



function M.DebugCanUse(self,textArg,otherArg)
	print("---------DebugCanUse------------------",textArg,otherArg)
end


function M.AddBadge(self,textArg,otherArg)
	self.parent:GetComponent(ServerOHOH.load.Server_BadgeCtrl()):AddBadge(tonumber(textArg))
end

function M.AddLevel(self,textArg,otherArg)
	self.parent:GetComponent(ServerOHOH.load.Server_ItemCtrl()):AddItem({base_level=textArg})
end

function M.AddPotions(self,textArg,otherArg)
	self.parent:GetComponent(ServerOHOH.load.Server_ItemCtrl()):AddItem({[textArg]=1},true,true)

end


function M.CreateOrbit(self,textArg,otherArg)
	-- local data={}
	-- for i=1,100 do
	-- 	table.insert(data,math.random(1,6))
	-- end
	-- local level=_G.CommonOHOH.load.Level().new(data,Workspace.Baseplate.Orbit.WorldCFrame)
	print("开始一次比赛---》")
	-- self.parent:GetComponent(_G.CommonOHOH.load.Common_TrackCtrl()):CreateTrack(1)
	self.car=_G.CommonOHOH.load.Car().new(self.parent,"10002_2","50002_2","20002_2","30002_2","40002_2")

    self.car:SetCFrame(Workspace.Baseplate.Car.WorldCFrame)
	-- -- self.car:SetCFrame(CFrame.new(Vector3.new(-69.15, 6.158, -4.27)))
	-- self.car:SetForwardSpeed(40)
    self.car:AnchoredSwitch(false)
	self.car:SetParent(Workspace)
	self.car:GetModel()
	print("self.car:GetModel()",self.car:GetModel())

end

function M.createCar(self,textArg,otherArg)

	if  self.car2 then
		print("2次点击")
		-- self.car2:SetEmitterStatus(false)
		self.car2:dtor()
		self.car2=nil
	end
	self.car=_G.CommonOHOH.load.Car().new(self.parent,"10002_1","50002_1","20001_1","30002_1","40001_1")

    self.car:SetCFrame(Workspace.Baseplate.Car.WorldCFrame)


	-- -- self.car:SetCFrame(CFrame.new(Vector3.new(-69.15, 6.158, -4.27)))
	-- self.car:SetForwardSpeed(40)
    self.car:AnchoredSwitch(false)
	self.car:SetParent(Workspace)
	self.car:GetModel()
	-- self.parent:GetComponent(_G.CommonOHOH.load.Common_TrackCtrl()):CreateTrack(1)

	self.car2=_G.CommonOHOH.load.LevelCar().new(self.parent,"10002_1","50002_1","20001_1","30002_1","40001_1")
	local SceneFolder=workspace:WaitForChild("Scene")
	local touch = nil
	for _,model in pairs(SceneFolder:GetChildren()) do
		for i = 1, 12 do
			local path=string.format("Parking.%s.Spawn",i) --碰撞体路径
			touch=ServerOHOH:GetPath_Loop(path,model)
			local isUsing = touch:GetAttribute("isUsing")
			if not isUsing then
				touch:SetAttribute("isUsing", true)
				break
			end
		end
	end
	local collide = self.car2:GetWeapon():GetTouchPart()
	collide.CanCollide = false
	print(" self.car2", self.car2)
    self.car2:SetCFrame(touch.CFrame)
	self.car2:AnchoredSwitch(false)
	self.car2:SetParent(Workspace)
	self.car2:start()
end


--------------------TestPVP-----------------------------------------
function M.UpdateELO(self,textArg,otherArg)
	print("----------UpdateELO--------------")
	_G.server:GetComponent(ServerOHOH.load.Server_PVPDataStoreCtrl()):UpdatePlayerPvpPool(tonumber(textArg),self.parent:GetUserId())

end

function M.GetELOData(self,textArg,otherArg)
	print("----------GetELOData--------------")

		
	if not textArg or textArg=="nil"  or textArg==""  then
		print("----------PrintData----------1----")

		local d=_G.server:GetComponent(ServerOHOH.load.Server_PVPDataStoreCtrl()):GetPvpDataStoreByRankId(self.parent:GetUserId())

		for k,v in pairs(d:GetPvpPlayer(10)) do
			print(v.key,v.value)
		end
	else
		print("----------PrintData---------2---",textArg)

		local d=_G.server:GetComponent(ServerOHOH.load.Server_PVPDataStoreCtrl()):GetPvpDataStoreByRankId(tonumber(textArg))
		for k,v in pairs(d:GetPvpPlayer(10)) do
			print(v.key,v.value)
		end
	end


end
function M.GetCars(self,textArg,otherArg)
	print("----------GetCars--------------")

	
	if not textArg or textArg=="nil"  or textArg==""  then
		print("----------PrintData----------1----")

		_G.server:GetComponent(ServerOHOH.load.Server_PVPDataStoreCtrl()):GetPlayerCarInfo(self.parent:GetUserId())
	else
		print("----------PrintData---------2---",textArg)

		_G.server:GetComponent(ServerOHOH.load.Server_PVPDataStoreCtrl()):GetPlayerCarInfo(tonumber(textArg))
	end

	-- _G.server:GetComponent(ServerOHOH.load.Server_PVPDataStoreCtrl()):GetPlayerCarInfo(tonumber(textArg))
end

function M.AddPoint(self,textArg,otherArg)
	print("----------AddPoint--------------")
	_G.server:GetComponent(ServerOHOH.load.Server_PVPDataStoreCtrl()):AddPoint(self.parent:GetUserId(),tonumber(textArg))

end

function M.PrintData(self,textArg,otherArg)

	if not textArg or textArg=="nil"  or textArg==""  then
		print("----------PrintData----------1----")

		_G.server:GetComponent(ServerOHOH.load.Server_PVPDataStoreCtrl()):PrintUserData(self.parent:GetUserId())
	else
		print("----------PrintData---------2---",textArg)

		_G.server:GetComponent(ServerOHOH.load.Server_PVPDataStoreCtrl()):PrintUserData(tonumber(textArg))
	end

end

function M.dtor(self)
	M.super.dtor(self);
end;

ServerEventManager:RegistHandle(EventList.DataDebug, function(player,cmd,...)
	player.debugTest_comp:Debug(cmd,...)
end)

return M;

